package biz.innovasoft.nodb.transaction;

import java.util.Date;

import org.prevayler.Transaction;

import biz.innovasoft.nodb.impl.GenericRepository;

public class RemoveIndexTransaction implements Transaction {

	private static final long serialVersionUID = 1L;
	
	private Class<?> clazz;
	private String indexPath;
	
	public RemoveIndexTransaction (Class<?> clazz) {
		this.clazz = clazz;
	}
	
	public RemoveIndexTransaction (Class<?> clazz, String stringPath) {
		this.clazz = clazz;
		this.indexPath = stringPath;
	}
	
	@Override
	public void executeOn(Object prevalentSystem, Date time) {
		GenericRepository repository = (GenericRepository)prevalentSystem;
		if (indexPath == null) {
			repository.removeIndex(clazz);
		} else {
			repository.removeIndex(clazz, indexPath);
		}
	}

}
